package com.cts.controller.admin;

import com.cts.annotation.OperationLogger;
import com.cts.entity.Tag;
import com.cts.model.dto.TagDTO;
import com.cts.model.vo.PageResultVO;
import com.cts.model.vo.Result;
import com.cts.service.BlogTagService;
import com.cts.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: CBlog
 * @package: com.cts.controller.admin
 * @className: TagAdminController
 * @author: chentongsheng
 * @description: TODO
 * @date: 2023/2/23 16:20
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin")
public class TagAdminController {

    @Autowired
    TagService tagService;

    @Autowired
    BlogTagService blogTagService;


    @OperationLogger("新增标签")
    @ApiOperation("新增标签")
    @PostMapping("/addTag")
    public Result addTag(@RequestBody Tag tag){
        Boolean result = tagService.save(tag);
        return Result.ok("添加成功");
    }

    @OperationLogger("更新标签")
    @ApiOperation("更新标签")
    @PostMapping("/updateTag")
    public Result updateTag(@RequestBody Tag tag){
        Boolean result = tagService.updateById(tag);
        return Result.ok("更新成功");
    }

    @OperationLogger("删除标签")
    @ApiOperation("删除标签")
    @PostMapping("/deleteTag")
    public Result deleteTag(@RequestBody Long id){
        tagService.removeById(id);
        blogTagService.removeById(id);
        return Result.ok("删除成功");
    }

    @OperationLogger("获取标签")
    @ApiOperation("获取标签")
    @PostMapping("/getTagList")
    public Result getTagList(@RequestBody TagDTO tagDTO){
        PageResultVO<Tag> tagPageResult = tagService.getTagList(tagDTO);
        return Result.ok("请求成功", tagPageResult);
    }

    @OperationLogger("获取标签字典")
    @ApiOperation("获取标签字典")
    @GetMapping("/getTagDict")
    public Result getTagDict(){
        List<Tag> tagDict = tagService.list();
        return Result.ok("请求成功",tagDict);
    }

}
